package guis;

import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;

import classes.Iterator;
import classes.Tableble;

import communication.Facade;

public abstract class RegisterPanel< T extends Tableble > extends JPanel
{
	private static final long		serialVersionUID	= -2238677678739841723L;

	protected JButton					editButton;
	protected JButton					findButton;
	protected JButton					insertButton;
	protected JButton					removeButton;
	protected JPanel					controlPanel;
	protected JPanel					formPanel;
	protected TablePanel< T >	tablePanel;

	protected JFrame					parent;
	protected Facade					facade;
	protected RegisterPanel< T >		self;

	public RegisterPanel( JFrame parent, Facade facede )
	{
		this.facade = facede;
		this.parent = parent;

		initialize();
		this.createPanels();
		this.createButtons();
		this.self = this;
	}

	private void initialize()
	{
		this.setLayout( null );
		this.setVisible( false );
		this.setSize( 800, 600 );
	}

	private void createPanels()
	{
		this.controlPanel = ComponentFactory.createJPanel( 145, 600, 0, 0, this );
		this.formPanel = ComponentFactory.createJPanel( 655, 600, 145, 0, this );
		controlPanel.setVisible( true );
		formPanel.setVisible( true );
	}

	private void createButtons()
	{
		this.insertButton = ComponentFactory.createJButton( "Inserir", true, 125, 125, 10, 10, new ImageIcon( "images/insert.png" ), controlPanel );
		this.editButton = ComponentFactory.createJButton( "Editar", false, 125, 125, 10, 145, new ImageIcon( "images/edit.png" ), controlPanel );
		this.removeButton = ComponentFactory.createJButton( "Remover", false, 125, 125, 10, 280, new ImageIcon( "images/remove.png" ), controlPanel );
		this.findButton = ComponentFactory.createJButton( "Buscar", true, 125, 125, 10, 415, new ImageIcon( "images/find.png" ), controlPanel );
		
		insertButton.setMnemonic( KeyEvent.VK_I );
		editButton.setMnemonic( KeyEvent.VK_E );
		removeButton.setMnemonic( KeyEvent.VK_R );
		findButton.setMnemonic( KeyEvent.VK_B );
	}

	public JTable getTable()
	{
		return tablePanel.getTable();
	}
	
	public abstract void loadTable( Iterator< T > iterator );
}